#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;


template <class T = int, int kCapacity = 10>
class Stack
{
public:
    Stack()
    : _top(-1)
    , _data(new T[kCapacity]())
    {
        cout << "Stack()" << endl;
    }

    ~Stack(){
        if(_data){
            delete [] _data;
            _data = nullptr;
        }
        cout << "~Stack()" << endl;
    }

    bool empty() const
    {
        return _top == -1;
    }
    bool full() const
    {
        return _top == kCapacity - 1;
    }
    void push(const T & t)
    {   
        if(!full()){
            _data[++_top] = t;
        }else{
            cout << "the Stack is full" << endl;
        }
    }

    void pop()
    {
        if(!empty()){
            --_top;
        }else{
        cout << "the Stack is empty" << endl;
        }
    }

    T top();
private:
    int _top;
    T * _data;
};

//将类模板的成员函数放到类外实现
//需要加上完整的模板声明
//包括类模板的名字
template <class T,int kCapacity>
T Stack<T,kCapacity>::top(){
    return _data[_top];
}

void test0(){
    Stack<int,5> sta1;
    cout << "is stack empty? " << sta1.empty() << endl;
    sta1.push(1);
    sta1.push(1);
    sta1.push(1);
    sta1.push(1);
    sta1.push(1);
    cout << "is stack full? " << sta1.full() << endl;

    Stack<string> sta2;
    Stack<> sta3;
}

int main(void){
    test0();
    return 0;
}
